package cn.tedu.cinema.hall.service.Impl;

import cn.tedu.cinema.hall.mapper.HallMapper;
import cn.tedu.cinema.hall.pojo.dto.HallQuery;
import cn.tedu.cinema.hall.pojo.dto.HallSaveParam;
import cn.tedu.cinema.hall.pojo.entity.Hall;
import cn.tedu.cinema.hall.pojo.vo.HallVO;
import cn.tedu.cinema.hall.service.HallService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class HallServiceImpl implements HallService {

    @Autowired
    HallMapper hallMapper;
    @Override
    public void saveHall(HallSaveParam hallSaveParam) {
        log.debug("开始处理【保存影厅的功能】");
        Hall hall = new Hall();
        BeanUtils.copyProperties(hallSaveParam,hall);
        if(hallSaveParam.getId()==null)
        {
         hall.setCreateTime(new Date());
         hallMapper.insert(hall);
        }else {
            hall.setUpdateTime(new Date());
            hallMapper.update(hall);
        }
    }

    @Override
    public void deleteHall(Long id) {
        log.debug("开始处理【删除影厅】业务,参数{}", id);
        hallMapper.delete(id);
    }

    @Override
    public List<HallVO> selectHall(HallQuery hallQuery) {
        log.debug("开始处理【查询影厅】业务,参数{}", hallQuery);
        List<HallVO> list = hallMapper.select(hallQuery);

        return list;
    }

}
